home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 201-225 / disk_222 / plplot / examples / example01.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  3KB  |  104 lines

  1. /* Demonstration program for PLPLOT: */
  2.  
  3. /* Plots three simple functions, each function occupies a separate page */
  4.  
  5. #include <stdio.h>
  6. #include <math.h>
  7.  
  8. static float xs[6] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
  9. static float ys[6] = {1.0, 4.0, 9.0, 16.0, 25.0, 36.0};
  10. static int space0 = 0;
  11. static int mark0 = 0;
  12. static int space1 = 1500;
  13. static int mark1 =1500;
  14.  
  15. main()
  16. {
  17.       int i;
  18.       float x[101], y[101];
  19.  
  20. /* Ask user to specify the output device */
  21.  
  22.       plstar(1,1);
  23.  
  24. /* Set up the viewport and window using PLENV. The range in X is */
  25. /* 0.0 to 6.0, and the range in Y is 0.0 to 30.0. The axes are */
  26. /* scaled separately (just = 0), and we just draw a labelled */
  27. /* box (axis = 0). */
  28.  
  29.       plenv(0.0,6.0,0.0,30.0,0,0);
  30.       pllab("(x)","(y)","\\frPLPLOT Example 1 - y=x\\u2");
  31.  
  32. /* Plot the data points */
  33.  
  34.       plpoin(6,xs,ys,9);
  35.  
  36.       for (i=0; i<60; i++) {
  37.         x[i]=0.1*(i+1);
  38.         y[i]= pow(x[i],2.);
  39.       }
  40.  
  41. /* Draw the line through the data */
  42.  
  43.       plline(60,x,y);
  44.  
  45. /*======================================================================*/
  46.  
  47. /* Set up the viewport and window using PLENV. The range in X is */
  48. /*  -2.0 to 10.0, and the range in Y is -0.4 to 2.0. The axes are */
  49. /*  scaled separately (just = 0), and we draw a box with axes */
  50. /*  (axis = 1). */
  51.  
  52.       plenv(-2.0,10.0,-0.4,1.2,0,1);
  53.       pllab("(x)","sin(x)/x","\\frPLPLOT Example 1 - Sinc Function");
  54.  
  55. /* Fill up the arrays */
  56.  
  57.       for (i=0; i<100; i++) {
  58.         x[i] = (i-19.0)/6.0;
  59.         y[i] = 1.0;
  60.         if (x[i] != 0.0) y[i] = sin(x[i])/x[i];
  61.       }
  62.  
  63. /* Draw the line */
  64.  
  65.       plline(100,x,y);
  66.  
  67. /*======================================================================*/
  68.  
  69. /* For the final graph we wish to override the default tick intervals, */
  70. /* and so do not use PLENV */
  71.  
  72.       pladv(0);
  73.  
  74. /* Use standard viewport, and define X range from 0 to 360 degrees, */
  75. /* Y range from -1.2 to 1.2. */
  76.  
  77.       plvsta();
  78.       plwind(0.0,360.0,-1.2,1.2);
  79.  
  80. /* Draw a box with ticks spaced 30 degrees apart in X, and 0.2 in Y. */
  81.  
  82.       plbox("bcnst",30.0,3,"bcnstv",0.2,2);
  83.  
  84. /* Superimpose a dashed line grid, with 1.5 mm marks and spaces. */
  85. /* plstyl expects a pointer!! */
  86.  
  87.       plstyl(1,&mark1,&space1);
  88.       plbox("g",30.0,3,"g",0.2,2);
  89.       plstyl(0,&mark0,&space0);
  90.  
  91.       pllab("Angle (degrees)","sine","\\frPLPLOT Example 1 - Sine function");
  92.  
  93.       for (i=0; i<101; i++ ) {
  94.         x[i] = 3.6 * i;
  95.         y[i] = sin(x[i]*3.141592654/180.0);
  96.       }
  97.  
  98.       plline(101,x,y);
  99.  
  100. /* Don't forget to call PLEND to finish off! */
  101.  
  102.       plend();
  103. }
  104.